/**************************************************************************** 
* 
* Copyright (c) 2023  C*Core -   All Rights Reserved  
* 
* THIS SOFTWARE IS DISTRIBUTED "AS IS," AND ALL WARRANTIES ARE DISCLAIMED, 
* INCLUDING MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* 
* PROJECT     : CCFC2011BC           
* DESCRIPTION : CCFC2011BC ECSM low level drivers code 
* HISTORY     : Initial version.
* @file     ecsm_lld.c
* @version  1.1
* @date     2023 - 02 - 20
* @brief    Initial version.
*
*****************************************************************************/
#include "ecsm_lld.h"
#include "intc_lld.h"
#include "flash_lld.h"

/************************************************************************
 *    ECC Configuration Register (ECR)
 *    Function definition
 ************************************************************************/
/*******************************************************************************
 * @brief      ECC Configuration Register (ECR).
 *             ER1BR: Enable SRAM 1-bit Reporting
 *             EF1BR: Enable Flash 1-bit Reporting
 *             ERNCR: Enable SRAM Non-Correctable Reporting
 *             EFNCR: Enable Flash Non-Correctable Reporting
 * @param[in]  errBit: (errBit & EEGR_ERRBIT_MAX)
 *             ecrSW: Enable or disable(uint8_t).
 * @param[out] None
 * @retval     0:success, other:fail
 * @notapi
 *******************************************************************************/
uint32_t ECSM_ECC_ECR_Config(uint8_t ecrSel, uint8_t ecrSW)
{
    if (ECR_EN == ecrSW)
    {
        ECSM.ECR.R |= ecrSel;
        return 0U;
    }
    if (ECR_DIS == ecrSW)
    {
        ECSM.ECR.R &= ~ecrSel;
        return 0U;
    }

    return 1U;
}


/************************************************************************
 *    ECC Error Generation Register (EEGR)
 *    Function definition
 ************************************************************************/
/*******************************************************************************
 * @brief      FRC1BI(Force SRAM Continuous 1-bit Data Inversions) 
 *              + Error Bit Position.
 * @param[in]  errBit: (errBit & EEGR_ERRBIT_MAX)
 * @param[out] None
 * @retval     None
 * @notapi
 *******************************************************************************/
void ECSM_SRAM_Force1BitCont(uint16_t errBit)
{
    ECSM.EEGR.R = ((errBit) & EEGR_ERRBIT_MAX) | EEGR_FRC1BI;
}

/*******************************************************************************
 * @brief      FR11BI(Force SRAM One 1-bit Data Inversion) 
 *              + Error Bit Position.
 * @param[in]  errBit: (errBit & EEGR_ERRBIT_MAX)
 * @param[out] None
 * @retval     None
 * @notapi
 *******************************************************************************/
void ECSM_SRAM_Force1BitOne(uint16_t errBit)
{
    ECSM.EEGR.R = ((errBit) & EEGR_ERRBIT_MAX) | EEGR_FR11BI;
}

/*******************************************************************************
 * @brief      FRCNCI(Force SRAM Continuous Non-correctable Data Inversions) 
 *              + Error Bit Position.
 * @param[in]  errBit: (errBit & EEGR_ERRBIT_MAX)
 * @param[out] None
 * @retval     None
 * @notapi
 *******************************************************************************/
void ECSM_SRAM_Force2BitCont(uint16_t errBit)
{
    ECSM.EEGR.R = ((errBit) & EEGR_ERRBIT_MAX) | EEGR_FRCNCI;
}

/*******************************************************************************
 * @brief       FR1NCI(Force SRAM One Non-correctable Data Inversions) 
 *              + Error Bit Position.
 * @param[in]  errBit: (errBit & EEGR_ERRBIT_MAX)
 * @param[out] None
 * @retval     None
 * @notapi
 *******************************************************************************/
void ECSM_SRAM_Force2BitOne(uint16_t errBit)
{
    ECSM.EEGR.R = ((errBit) & EEGR_ERRBIT_MAX) | EEGR_FR1NCI;
}


/*******************************************************************************
 * @brief      Force SRAM Data Inversions stop.
 * @param[in]  None
 * @param[out] None
 * @retval     None
 * @notapi
 *******************************************************************************/
void ECSM_SRAM_ForceStop(void)
{
    ECSM.EEGR.R = 0x0000U;
}

